﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="StandMeetingAdd.aspx.cs"
    Inherits="Meeting.Web.Admin.MeetingStand.StandMeetingAdd" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>常设会议设置</title>
    <script type="text/javascript" src="../../Scripts/jquery-1.8.2.min.js"></script>
    <link href="../../Css/main.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" type="text/css" href="../../Scripts/themes/icon.css" />
    <link rel="stylesheet" href="../../Css/zTreeStyle/zTreeStyle.css" type="text/css" />
    <link rel="stylesheet" type="text/css" href="../../Scripts/themes/cupertino/easyui.css" />
    <script type="text/javascript" src="../../Scripts/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="../../Scripts/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="../../Scripts/common.js"></script>
    <script type="text/javascript" src="../../Scripts/jquery.ztree.core-3.5.min.js"></script>
    <script type="text/javascript" src="../../Scripts/jquery.ztree.excheck-3.5.js"></script>
    <!--ardialog-->
    <script type="text/javascript" src="../../Scripts/artDialog4.1.6/artDialog.js?skin=blue"></script>
    <script type="text/javascript" src="../../Scripts/artDialog4.1.6/plugins/iframeTools.js"></script>
    <script src="../../Scripts/Json2.js" type="text/javascript"></script>
    <script type="text/javascript">
        var selCount = 0;
        var selectPerson = new Array();//已选择人员数组
        var zTree;
        var CategoryId = "";
        var bFlagEdit = false;
        //树初始化 
        var setting = { check: { enable: true },
            data: {
                simpleData: {
                    enable: true,
                    idKey: "account",
                    pIdKey: "parent",
                    rootPId: "0"
                },
                callback: { onCheck: zTreeOnCheck}//, onClick: onClick 
            }
        };
        function onClick(event, treeId, treeNode) {

        }

        function DelGrid(tn) {
            var rows = $('#tbEmployee').datagrid('getRows');

            for (i = 0; i < rows.length; i++) {
                var row = rows[i];
                if (row.EmployeeId == tn.account) {
                    var index = $('#tbEmployee').datagrid('getRowIndex', row);
                    $('#tbEmployee').datagrid('deleteRow', index);
                    break;
                }
            }
        }
        //树选中事件
        function zTreeOnCheck(event, treeId, treeNode) {

            nodes = zTree.getChangeCheckedNodes();
            for (var i = 0, l = nodes.length; i < l; i++) {
                nodes[i].checkedOld = nodes[i].checked;
                var treeNode = nodes[i];
                if (treeNode.checked == true) {
                    AppendGrid(treeNode);

                } else {
                    DelGrid(treeNode);
                }
            }
        }
        $(function () {
            // if (request("psnID") == "") window.location = defaultUrl;
            SetMeetingCategory();
            //浏览常设会议信息
            var method = request("method");
            if (method == "show") {
                Show();
            }

        });

        //设置会议类型
        function SetMeetingCategory() {
            $("#CategoryId").combobox(
            {
                url: 'StandMeetingOperation.ashx?method=GetMeetingCategory',
                valueField: 'Id',
                textField: 'Name',
                onSelect: function (rec) {

                    /*  var strs = rec.Id.split('#');
                    if (strs.length < 2) {
                    return;
                    }
                    CategoryId = strs[0]; //会议类型
                    var rolestr = strs[1];
                    $.ajax({
                    type: "POST",
                    url: "../SelectBase/SelectOperation.ashx?method=GetOAEmploy&role=" + rolestr,
                    dataType: "json",
                    success: function (data, textStatus) {
                    //alert(data);
                    zTree = $.fn.zTree.init($("#treeMain"), setting, data);
                    zTree.expandAll(true);
                    zTree.setting.check.chkboxType = { "Y": "ps", "N": "ps" };
                    zTree.setting.callback.onCheck = zTreeOnCheck;
                    // zTree.checkAllNodes(true);
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {

                    }
                    });*/
                }
            }
        );
        }

        function Show() {
            var id = request("Id");
            if (id == "" || id == null || id == undefined) {
                return;
            }
            //            $("#MeetingSave").hide();
            $("#MeetingAdd").hide();
            //            $("#editSort").hide();
            //            $("#editSelect").hide();
            //$("#role").hide();
            $.ajax({
                type: "POST",
                url: "StandMeetingOperation.ashx?method=GetMeetingById&Id=" + id,
                dataType: "json",
                success: function (data, textStatus) {
                    if (data) {
                        $("#Id").val(data[0].Id);
                        $.ajax({
                            type: "POST",
                            url: "StandMeetingOperation.ashx?method=GetMeetingCategory&Id=" + data[0].CategoryId,
                            dataType: "json",
                            success: function (d, textStatus) {
                                if (d.length > 0) {
                                    $("#CategoryId").combobox("setValue", d[0].Id);
                                    $("#CategoryId").combobox("setText", d[0].Name);
                                }
                            }
                        });
                        $("#CategoryId").combobox("disable");
                        $("#Name").val(data[0].Name);
                        $("#Comment").val(data[0].Comment);
                        $("#IsActive").combobox("setValue", data[0].IsActive);

                        //获取已选人员
                        $("#tbEmployee").datagrid(
                        {
                            url: "StandMeetingOperation.ashx?method=GetMeetingEmployeeById&Id=" + id

                        });
                    }
                }
            });
        }

        //获取已选择人员
        function GetSelectEmployee() {
            var rows = $('#tbEmployee').datagrid('getRows');
            if (rows.length < 1) return "";
            for (i = 0; i < rows.length; i++) {
                var ed = $('#tbEmployee').datagrid('getEditor', { index: i, field: 'Sort' });

                if (ed != null && $(ed.target).val() == "") $(ed.target).val("10");
                $('#tbEmployee').datagrid('endEdit', i);
            }
            var data = $("#tbEmployee").datagrid("getData");
            if (data) return data.rows;
            return "";
        }
        function EditSort() {
            var rows = $('#tbEmployee').datagrid('getRows');
            for (i = 0; i < rows.length; i++) {
                $('#tbEmployee').datagrid('beginEdit', i);
            }
        }

        //添加与会人员
        function AddEmployee() {
            var categoryValue = $("#CategoryId").combobox("getValue");
            var strs = categoryValue.split('#');
            if (strs.length < 2) {
                $.messager.alert("提示", "请选择会议类型");
                return;
            }
            CategoryId = strs[0]; //会议类型
            var rolestr = strs[1];
            if (rolestr == "" || rolestr == undefined) {
                $.messager.alert("提示", "请选择会议类型");
                return;
            }
            
            var radStr = Math.random();
            var url = "../SelectBase/SelectOAUser.aspx" + '?Radstr=' + radStr + "&RoleId=" + rolestr;
            art.dialog.open(url, {
                id: 'AddEmployee', title: '选择参会人', width: 500, height: 430, lock: true,
                close: function () {
                    var flag = art.dialog.data('result'); // 读取返回值True表示正确
                    if (flag) {
                        var selNodeJson = art.dialog.data('selNode'); // 读取人员选择返回值
                        //  alert(selNodeJson);
                        if (selNodeJson != "") {
                            try {
                                //alert(selNodeJson);
                                var data = JSON.parse(selNodeJson);
                                //alert(selNodeJson);
                                if (request("method") != "show") {  //编辑状态
                                    DelAll();
                                }
                                //
                                for (n = 0; n < data.length; n++) {
                                    if (CheckExits(data[n].EmployeeId) == 0) {
                                        // alert(n);
                                        $('#tbEmployee').datagrid('appendRow', data[n]);
                                    }
                                }
                            } catch (ex) { alert(ex.toString()); }
                        }
                    }
                }
            }, true);
        }
        //删除全部
        function DelAll() {
            var rows = $('#tbEmployee').datagrid('getRows');

            for (i = rows.length - 1; i >= 0; i--) {
                $('#tbEmployee').datagrid('deleteRow', i);
            }
        }
        //判断是否已经选中
        function CheckExits(eid) {
              var rows = $('#tbEmployee').datagrid('getRows');
              for (i = 0; i < rows.length; i++) {
                  if (rows[i].EmployeeId == eid) {
                    return 1;
                }
            }
            return 0;
        }


        function AppendGrid(tn) {



        }
        //保存常设会议信息       
        function SaveStandMeeting() {
            //验证表单
            $("#CategoryId").combobox("enable");
            if ($("#form1").form('validate') == false) {
                return;
            }

            //获取选中人员
            var selEmployee = GetSelectEmployee();
            if (selEmployee == "") {
                $.messager.alert("提示", "请选择参会人员");
                return;
            }
            selEmployee = JSON.stringify(selEmployee);
            //
            var categoryValue = $("#CategoryId").combobox("getValue");
            var strs = categoryValue.split('#');
            if (strs.length < 2) {
                $.messager.alert("提示", "请选择会议类型");
                return;
            }
            CategoryId = strs[0]; //会议类型
            var rolestr = strs[1];
            if (rolestr == "" || rolestr == undefined) {
                $.messager.alert("提示", "请选择会议类型");
                return;
            }

            //
            var Id = $("#Id").val();
            var Name = $("#Name").val();
            var Comment = $("#Comment").val();
            var IsActive = $("#IsActive").combobox("getValue");

            //
            var postData = { Id: Id, Name: Name, Comment: Comment, IsActive: IsActive,
                selEmployee: selEmployee, CategoryId: CategoryId
            };
            //提交
            $("#CategoryId").combobox("disable");
            $.post("StandMeetingOperation.ashx?method=SaveStandMeeting", postData, function (data) {
                if (data.success == true) {
                    $("#Id").val(data.Message); //成功后记录会议ID
                    $.messager.alert("提示", "保存成功");
                    art.dialog.close();
                } else {
                    $.messager.alert("提示", data.Message);
                }
            });
        }

        function NewStandMeeting() {
            window.location.reload();

        }
    </script>
    <style type="text/css">
        #role
        {
            font-size: 14px;
        }
        #role input
        {
            border: 0;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table class="showView1" cellpadding="1" cellspacing="1" align="center">
            <tr>
                <td class="title">
                    <span style="color: Red;">*</span> 会议类型:
                </td>
                <td class="td_Modify1">
                    <select id="CategoryId" class="easyui-combobox" style="width: 403px;" editable="false"
                        required="true">
                    </select>
                </td>
            </tr>
            <tr>
                <td class="title">
                    <span style="color: Red;">*</span> 会议名称:
                </td>
                <td class="td_Modify1">
                    <input type="hidden" id="Id" /><!--会议ID-->
                    <input id="Name" name="Name" type="text" class="easyui-validatebox" required="true"
                        style="width: 400px" />
                </td>
            </tr>
            <%--  <tr>
                <td class="title">
                    可选人员
                </td>
                <td class="td_Modify1">
                    <div style="width: 400px; max-height: 180px; min-height: 170px; text-align: left;
                        overflow: auto;">
                        <ul id="treeMain" class="ztree">
                        </ul>
                    </div>
                </td>
            </tr>--%>
            <tr>
                <td class="title">
                    <span style="color: Red;">*</span>参会人员
                </td>
                <td class="td_Modify1">
                    <a id="editSelect" class="easyui-linkbutton" onclick="AddEmployee();">选择参会人</a>
                    <a id="editSort" class="easyui-linkbutton" onclick="EditSort();">编辑排序</a>
                    <table id="tbEmployee" class="easyui-datagrid" singleselect="true" style="width: 400px;
                        height: 300px; font-size: 16px;">
                        <thead>
                            <tr>
                                <th data-options="field:'EmployeeId',hidden:true">
                                    编号
                                </th>
                                <th data-options="field:'EmployeeName',width:80">
                                    姓名
                                </th>
                                <th data-options="field:'RoleId',hidden:true">
                                    编号
                                </th>
                                <th data-options="field:'EmployeeTitle',width:70 ">
                                    职务
                                </th>
                                <th data-options="field:'Mobile',width:100">
                                    手机
                                </th>
                                <th data-options="field:'Sort',width:80,editor:'text'">
                                    排序
                                </th>
                                <th data-options="field:'actionColumn2',width:120,formatter:formatDelete">
                                    删除
                                </th>
                            </tr>
                        </thead>
                    </table>
                </td>
            </tr>
            <tr>
                <td class="title">
                    备注信息:
                </td>
                <td class="td_Modify1">
                    <input id="Comment" name="Comment" type="text" class="easyui-validatebox" style="width: 400px" />
                </td>
            </tr>
            <tr>
                <td class="title">
                    是否有效:
                </td>
                <td class="td_Modify1">
                    <select id="IsActive" class="easyui-combobox" name="vcount" value="1" style="width: 403px;">
                        <option value="1">有效</option>
                        <option value="0">无效</option>
                    </select>
                </td>
            </tr>
            <tr>
                <td class="title">
                    &nbsp;
                </td>
                <td class="td_Modify1">
                    <a id="MeetingSave" class="easyui-linkbutton" onclick="SaveStandMeeting();">保存常设会议</a>
                    <a id="MeetingAdd" class="easyui-linkbutton" onclick="NewStandMeeting();">继续添加</a>
                </td>
            </tr>
        </table>
        <script type="text/javascript">
            function formatDelete(val, row) {
                return "<a href='#' class='easyui-linkbutton' onclick=\"DeleteData('" + row.EmployeeId + "');\"  >删除</a> ";
            }

            function DeleteData(Id) {
                $.messager.confirm("询问", "确定要删除吗？", function (c) {
                    if (!c) return;
                    var row = $("#tbEmployee").datagrid('getSelected');
                    var index = $("#tbEmployee").datagrid('getRowIndex', row)
                    $('#tbEmployee').datagrid('deleteRow', index);

                });
            }
        </script>
    </div>
    </form>
</body>
</html>
